//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __ELA_SEMAPHORE_H__
#define __ELA_SEMAPHORE_H__

#include "ddk.h"
#include "mutex.h"

struct semaphore
{
    IMutex *m_lock;
};

#define init_MUTEX(sem) do {(sem)->m_lock = new CMutex; \
                        assert((sem)->m_lock); \
                        (sem)->m_lock->AddRef(); \
                         }while(0)
#define init_MUTEX_LOCKED(sem, wr) do {init_MUTEX(sem);(sem)->m_lock->Lock(wr);} while(0)
#define down(sem, wr) (sem)->m_lock->Lock(wr)
#define down_interruptible(sem, wr) ((sem)->m_lock->Lock(wr))
#define down_trylock(sem, wr) (sem)->m_lock->TryLock(wr)
#define up(sem) (sem)->m_lock->Unlock()
#define delete_MUTEX(sem) (sem)->m_lock->Release()

#endif  /* __ELA_SEMAPHORE_H__ */
